package com.suxin.ratelimit.v2.config;

import com.suxin.ratelimit.v2.handler.DistributedRateLimitHandler;
import com.suxin.ratelimit.v2.handler.RateLimitHandler;
import com.suxin.ratelimit.v2.handler.StandRateLimitHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author Tang
 * @classname RateLimitConfig
 * @description [  ]
 * @date 2022/2/9 16:34
 */
public class RateLimitConfig {

    public static class StandRateLimitConfig {
        @Bean
        public RateLimitHandler rateLimitHandler() {
            return new StandRateLimitHandler();
        }
    }

    public static class DistributedRateLimitConfig {
        @Bean
        @ConditionalOnClass(value = {RedisTemplate.class})
        public RateLimitHandler rateLimitHandler() {
            return new DistributedRateLimitHandler();
        }
    }

}